package com.aaa.medicine.controller;


import com.aaa.entity.Provider;
import com.aaa.medicine.service.IProviderService;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 供应商信息表 前端控制器
 * </p>
 *
 * @author 王雪桂
 * @since 2023-03-28
 */
@RestController
@RequestMapping("medicine/provider")
public class ProviderController {
@Autowired
private IProviderService iProviderService;
@GetMapping("getAll")
    public Result getAll(Page page,Provider provider){
    QueryWrapper<Provider> queryWrapper = new QueryWrapper();
        if (StringUtils.isNotBlank(provider.getProviderName())){
                queryWrapper.like("provider_name",provider.getProviderName());
        }
    if (StringUtils.isNotBlank(provider.getContactName())){
        queryWrapper.like("contact_name",provider.getContactName());
    }
    if (StringUtils.isNotBlank(provider.getContactTel())){
        queryWrapper.like("contact_tel",provider.getContactTel());
    }
    if (StringUtils.isNotBlank(provider.getStatus())){
        queryWrapper.like("status",provider.getStatus());
    }
    Page page1 = iProviderService.page(page, queryWrapper);
        return new Result(page1);
}
    //根据id删除
    @DeleteMapping("delById/{providerId}")
    public Result delById(@PathVariable Integer providerId){
        return new Result(iProviderService.removeById(providerId));
    }
    //添加
    @PostMapping("addStockProducerMapper")
    public Result addStockProducerMapper(@RequestBody Provider provider){
        return new Result(iProviderService.saveOrUpdate(provider));
    }

    //批量删除
    @PostMapping("delByIds")
    public Result delById(@RequestBody List<Provider> provider){
        provider.forEach((Provider provider1)->{
            boolean b = iProviderService.removeById(provider1.getProviderId());
        });
        return new Result(200,"");
    }
    //Purchase 供应商下拉框
    @GetMapping("getAll1")
    public Result<List<Provider>> getAll1(){
        List<Provider> list = iProviderService.list();
        return new Result(list);
    }

}

